package com.inossem.warehousestorage_inossem.activity.inventory.chuangyou;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.inossem.utils.base.Utils;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.activity.inventory.extre.InventoryExtre;
import com.inossem.warehousestorage_inossem.bean.inventory.chuangyou.InventoryCommitBean;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.request.inventory.chuangyou.InventoryCommitRequest;
import com.inossem.warehousestorage_inossem.utils.BaseInteface;
import com.inossem.warehousestorage_inossem.utils.InventoryUtils;
import com.inossem.warehousestorage_inossem.utils.SPUtils;

/**
 * 提交
 *
 * @author 詹建宇
 * @time on 2018/4/2 19:21
 * @email jianyu.zhan@inossem.com
 */
public class InventoryCommitActivity extends BaseActivity implements BaseInteface {

    private TextView title;
    private TextView noTv;
    private TextView personTv;
    private TextView timeTv;
    private TextView shouldTv;
    private TextView alreadyTv;
    private TextView commitTv;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        super.onCreateImpl(savedInstanceState);
        setContentView(R.layout.cy_activity_inventory_commit);

        initView(this);
        initData(this);
    }

    @Override
    public void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        noTv = (TextView) activity.findViewById(R.id.noTv);
        personTv = (TextView) activity.findViewById(R.id.personTv);
        timeTv = (TextView) activity.findViewById(R.id.timeTv);
        shouldTv = (TextView) activity.findViewById(R.id.shouldTv);
        alreadyTv = (TextView) activity.findViewById(R.id.alreadyTv);
        commitTv = (TextView) activity.findViewById(R.id.nextStep);
    }

    @Override
    public void initData(Activity activity) {
        String stocktake_id = getIntent().getStringExtra(InventoryExtre.STOCKTAKE_ID);
        title.setText("提交");
        personTv.setText(SPUtils.getName(activity));
        noTv.setText(stocktake_id);
        timeTv.setText(InventoryUtils.getTime());
        shouldTv.setText(getIntent().getStringExtra(InventoryExtre.SHOULD_NUM));
        alreadyTv.setText(getIntent().getStringExtra(InventoryExtre.ALREADY_NUM));

        commitTv.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                InventoryCommitRequest.request(activity, stocktake_id, new GsonBeanListener<InventoryCommitBean>() {
                    @Override
                    public void onSuccess(InventoryCommitBean bean) {
                        Utils.middleToast(activity, "提交成功");
                        finish();
                    }
                });
            }
        });
    }
}
